home *** CD-ROM | disk | FTP | other *** search
- /*
- * Object - the root class, inherited eventually by all classes.
- *
- * Copyright © John Wainwright 1988
- *
- * Supers : None.
- *
- * Class Vars : None
- *
- * Class Methods : None
- *
- * Methods :
- *
- * new - dummy new.
- * className - returns class name String
- */
-
- #include <stdio.h>
- #include "oic.h"
- #include "generics.h"
-
- class Object; /* root Object class */
-
- /* -------------------- Object Instance methods ---------------------------- */
-
- static object
- _new(self)
- object self;
- {
- return self;
- }
-
- static object
- _className(self)
- object self;
- {
- return New(String, ClassOf(self)->c_name);
- }
-
- static void
- _dispose(self)
- object self;
- {
- free(self);
- }
-
- static object
- _print(self)
- object self;
- {
- object replist = repList(self);
-
- print(replist);
- deepDispose(replist);
- }
-
- static object
- _repList(self)
- object self;
- {
- register object p;
- register int i, l;
- object replist;
- char buf[100];
-
- replist = New(Replist, "<", ">", " ");
- sprintf(buf, "%s:", ClassNameOf(self));
- append(replist, New(String, buf));
- l = ClassOf(self)->c_allocz / sizeof(object);
- for (p = self + 1, i = 1; i < l; i++, p++)
- if (IsObj(*p))
- append(replist, repList(*p));
- else
- {
- sprintf(buf, "%8.8lx", *p);
- append(replist, New(String, buf));
- }
- return replist;
- }
-
- static object
- _cantDo(self)
- object self;
- {
- fprintf(stderr, "cant do this method\n");
- return END;
- }
-
- static void
- _map(self, dummy, f)
- object self;
- char *dummy;
- void (**f)();
- {
- object seq, item;
-
- for (seq = sequence(self); item = next(seq); )
- (**f)(item);
- }
-
- static object
- _allInstances()
- {
- return New(List, END);
- }
-
- static object
- _deepInstances()
- {
- return New(List, END);
- }
-
- static int
- _eq(self, ivs, other)
- object self;
- char *ivs;
- object *other;
- {
- return (ClassOf(self) == ClassOf(*other) &&
- ClassOf(self)->c_allocz == ClassOf(*other)->c_allocz &&
- strncmp(self, *other, ClassOf(self)->c_allocz));
- }
-
- /* ------------------- Init the Object class ------------------------------- */
-
- /*
- * note that the Object has already been made in the ONLY function
- * that should call this: _InitRootClasses in obj.c
- */
-
- _InitObject()
- {
- AddMethods(Object,
- eqGeneric, _eq,
- newGeneric, _new,
- classNameGeneric, _className,
- printGeneric, _print,
- repListGeneric, _repList,
- disposeGeneric, _dispose,
- cantDoGeneric, _cantDo,
- mapGeneric, _map,
- allInstancesGeneric, _allInstances,
- deepInstancesGeneric, _deepInstances,
- END);
- }
-
-